<?php

namespace App\Models;

class Order extends BaseModel
{
    protected $table = 'orders';
    protected $fillable = [
        'order_no',
        'title',
        'user_id',
        'goods_id',
        'coupon_user_id',
        'amount',
        'amount_les',
        'amount_all',
        'price',
        'num',
        'pay_time',
        'notify_data',
        'status',
        'remark',
        'address_name',
        'address_phone',
        'address',
    ];

    public static $EnumStatus = [
        0 => '待支付', 1 => '待发货', 2 => '待收货', 3 => "待评价",
    ];

    public function userinfo()
    {
        return $this->hasOne(User::class, 'id', 'user_id')->select('id', 'nickname','avatar');
    }

    public function seller()
    {
        return $this->hasOneThrough(User::class, Goods::class, 'id','id',"goods_id", 'user_id')
            ->select('users.id', 'users.nickname','users.avatar');
    }

    public function goods()
    {
        return $this->hasOne(Goods::class, 'id', 'goods_id');
    }

    public function user()
    {
        return $this->hasOne(User::class, 'id', 'user_id');
    }
}
